package com.mg.controller;

import com.github.pagehelper.PageInfo;
import com.mg.common.Constants;
import com.mg.dto.RevenueRecordDto;
import com.mg.dto.SimpleResult;
import com.mg.model.RevenueRecord;
import com.mg.model.User;
import com.mg.service.RevenueRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by mg1213 on 2018/3/18.
 */
@Controller
@RequestMapping("/revenueRecord")
public class RevenueRecordController {
    @Autowired
    private RevenueRecordService revenueRecordService;

    @RequestMapping(value = "/user/selectRecordPageInfo")
    @ResponseBody
    public PageInfo<RevenueRecordDto> selectRecordPageInfo(RevenueRecordDto dto, int limit, int start, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute(Constants.USER_INFO);
        dto.setUserId(user.getId());
        return revenueRecordService.selectRecordPageInfo(dto, start, limit);
    }

    @RequestMapping(value = "/admin/selectPageInfo")
    @ResponseBody
    public PageInfo<RevenueRecordDto> selectPageInfo(RevenueRecordDto dto, int limit, int start) {
        return revenueRecordService.selectPageInfo(dto, start, limit);
    }

    @RequestMapping(value = "/admin/insertRevenueRecord")
    @ResponseBody
    public SimpleResult insertRevenueRecord(RevenueRecord record) {
        return revenueRecordService.insertRevenueRecord(record);
    }

    @RequestMapping(value = "/admin/updateRevenueRecord")
    @ResponseBody
    public SimpleResult updateRevenueRecord(RevenueRecord record) {
        return revenueRecordService.updateRevenueRecord(record);
    }
    @RequestMapping(value = "/admin/createRevenueRecord")
    @ResponseBody
    public SimpleResult createRevenueRecord(RevenueRecordDto record) {
        return revenueRecordService.createRevenueRecord(record);
    }

    @RequestMapping(value = "/admin/deleteRevenueRecord")
    @ResponseBody
    public SimpleResult deleteRevenueRecord(String ids) {
        return revenueRecordService.deleteRevenueRecord(ids);
    }

}
